
$(function () {
	
	if ( vaStatus == "notFind"){
		$('#myModalMessage').modal('show');
	}
});
// check button click
function checkButtonClick(button) {	
	if(button == "btn_search_account"){
		document.getElementById("btn_search_account").value = "yes";
	} else if (button == "btn_save"){
		document.getElementById("btn_save").value = "yes";		
	} //	else if ( button == "vaBtn_fresh"){
//		document.getElementById("vaBtn_fresh").value = "yes";
//	}
}

// set hide data when onChange in  inputPayerName and inputPayerAddress
function setPayNameAndAddress(){
	document.getElementById("vaHidePayerName").value = document.getElementById("inputPayerName").value;;
	document.getElementById("vaHideAddress").value = document.getElementById("inputPayerAddress").value;
}

// when on click close button from screen
function goBackHistory(pnPageRedirect){
	var pageRedirect;
	if (pnPageRedirect != null){
		pageRedirect = pnPageRedirect;
	} else {
		pageRedirect = -1;
	}		
	history.go(pageRedirect);
	$.getJSON('CS51001Srvl', { btn_closePage: "yes", url_address:$("#url_address").val(), agent_browser :$("#agent_browser").val()}, function(result) {
		
	});
}

function calculateOnChecked() {
	var vaDataOnChecked = '' ;
	var inputElements = document.getElementsByClassName('chkChoose');
	var vaCheckedStatus = 'no';

	// get checked data and add to Array
	for(var i=0; inputElements[i]; ++i){
	      if(inputElements[i].checked){
	    	  vaDataOnChecked += inputElements[i].value+",";
	    	  vaCheckedStatus = 'yes';
	      }
	}
	
	// is all, no checked 
	if ( vaCheckedStatus == 'no'){
		document.getElementById("vaSpanGrabageTotal").innerHTML = 0;	
		document.getElementById("vaSpanWasteWaterTotal").innerHTML = 0;	
		document.getElementById("vaSpanOther").innerHTML = 0;	
		document.getElementById("vaSpanVatTotal").innerHTML = 0;	
		document.getElementById("vaSpanBillAmountTotal").innerHTML = 0;	
		document.getElementById("vaSpanSumTotal").innerHTML = 0;	
		document.getElementById("vnSumTotal").innerHTML = 0;	
	}
	
	// call CS51001Srvl  to calculate
	$.getJSON('CS51001Srvl', { inputPenalty: document.getElementById("inputPenalty").value, voArrCheckedValue: vaDataOnChecked, url_address:$("#url_address").val(), agent_browser :$("#agent_browser").val() }, function(dataResult) {
		document.getElementById("vaSpanGrabageTotal").innerHTML = dataResult.voJSonResult[0];	
		document.getElementById("vaSpanWasteWaterTotal").innerHTML = dataResult.voJSonResult[1];	
		document.getElementById("vaSpanOther").innerHTML = dataResult.voJSonResult[2];	
		document.getElementById("vaSpanVatTotal").innerHTML = dataResult.voJSonResult[3];	
		document.getElementById("vaSpanBillAmountTotal").innerHTML = dataResult.voJSonResult[4];	
		document.getElementById("vaSpanSumTotal").innerHTML = dataResult.voJSonResult[5];	
		document.getElementById("vnSumTotal").innerHTML = dataResult.voJSonResult[6];	
	});
}

//------- validation data on submit
function validateFormScreen() {
	var error = false;
	var inputElements = document.getElementsByClassName('chkChoose');
	var chkNotError = false;
	for(var i=0; inputElements[i]; ++i){
	      if(inputElements[i].checked){
	    	  chkNotError = true;
	      }
	}
	
	if (document.getElementById("inputPayerName").value == "") {
		document.getElementById("vaSpanErrorMsg").innerHTML="กรุณากรอก ชื่อ - นามสกุล";
		$('#myModalMessageConfirm').modal('hide');
		$('#myModalValidateError').modal('show');
		$("#inputPayerName").focus();
		error = true;
	} else	if (document.getElementById("inputPayerAddress").value == "") {
		document.getElementById("vaSpanErrorMsg").innerHTML="กรุณากรอก ที่อยู่ผู้ชำระเงิน";
		$('#myModalMessageConfirm').modal('hide');
		$('#myModalValidateError').modal('show');
		$("#inputPayerAddress").focus();
		error = true;
	} else if ( chkNotError == false) {
		document.getElementById("vaSpanErrorMsg").innerHTML="กรุณาเลือกรายการชำระเงิน";
		$('#myModalMessageConfirm').modal('hide');
		$('#myModalValidateError').modal('show');
		$("#chkChoose").focus();
		error = true;
	}
	if (error) return false;
	else return true;
}